unit uFiend;

interface

uses
  uObject, SysUtils;

type
  TFiend = Record
    Xoff: integer;
    Yoff: integer;
    DIR: integer;
    moving: boolean;
  End;

function getTFiend(obj: TGameObject): TFiend;
function setTFiend(fiend: TFiend): string;

implementation

function getTFiend(obj: TGameObject): TFiend;
var
  i, j, x, y, d: integer;
  m: boolean;
  s, s1: String;
  f: TFiend;
begin
  s := obj.text2;
  s1 := '';
  j := 0;
  for i := 1 to length(s) do
    begin
      if (s[i] = '|') then
        begin
          if (j = 0) then x := StrToInt(s1);
          if (j = 1) then y := StrToInt(s1);
          if (j = 2) then d := StrToInt(s1);
          if (j = 3) then
            begin
              if (s1 = '0') then m := false
              else if (s1 = '1') then m := true;
            end;
          inc(j);
          s1 := '';
        end
      else
        begin
          s1 := s1 + s[i];
        end;
    end;
  f.Xoff := x;
  f.Yoff := y;
  f.DIR := d;
  f.moving := m;
  result := f;
end;

function setTFiend(fiend: TFiend): string;
var s: string;
begin
  s := '0';
  if(fiend.moving) then s := '1';
  result := IntToStr(fiend.Xoff) + '|' + IntToStr(fiend.Yoff) + '|' + IntToStr(fiend.DIR) + '|' + s + '|';
end;

end.
